function parseArgs(isVueCli) {
  const args = process.argv.slice(isVueCli ? 3 : 2);
  const upper = (_, c) => c.toUpperCase();
  const result = { _: [] };

  for (let i = 0, l = args.length; i < l; ++i) {
    let arg = args[i];
    let key, val, next, k;
    if (/^--.+/.test(arg)) {
      (arg = arg.substring(2)), (k = arg.indexOf('='));
      if (k > -1) {
        (key = arg.substring(0, k)), (val = arg.substring(k + 1));
      } else {
        (key = arg), (val = true);
        if (i < l && (next = args[i + 1]) && !/^-.+/.test(next)) {
          (val = next), i++;
        }
      }
      result[key] = val;
      result[key.replace(/-([a-z])/g, upper)] = val;
    } else if (/^-[^-]+/.test(arg)) {
      // NOTE: skip aliases
    } else {
      result._.push(arg);
    }
  }
  return result;
}

module.exports = parseArgs;
